
package de.uni.wuppertal.server.http;

import java.util.HashMap;
import java.util.LinkedList;

/**
 * @author Martin Schröder
 * @author Patrik Nordsiek
 */
abstract public class HTTPHeaders
{
	protected HashMap<String, LinkedList<String>> headers = new HashMap<String, LinkedList<String>>();
	
	public boolean hasHeader(String name)
	{
		return headers.containsKey(name.toLowerCase());
	}
	
	public LinkedList<String> getHeader(String name)
	{
		return headers.get(name.toLowerCase());
	}
	
	public void setHeader(String name, String value)
	{
		setHeader(name, value, true);
	}
	
	public void setHeader(String name, String value, boolean overwrite)
	{
		String n = name.toLowerCase();
		
		if(!headers.containsKey(n))
		{
			headers.put(n, new LinkedList<String>());
			
			headers.get(n).add(value);
		}
		else
		{
			if(overwrite)
			{
				headers.get(n).retainAll(new LinkedList<String>());
			}
			
			headers.get(n).add(value);
		}
	}
	
	public void removeHeader(String name)
	{
		headers.get(name.toLowerCase()).retainAll(new LinkedList<String>());
	}
}
